/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = apmtest_loader.c                                   */
/*  NOTE      =                                                    */
/*  DATE      = 2014/09/30 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "frmem.h"

int load_raw_file(char *filename, char **buffer, long *filelen)
{
    FILE *fp;

    if( (fp=fopen(filename,"rb"))== NULL )
    {
        printf("Can not open %s!\n",filename);
        return 1;
    }

    fseek(fp, 0, SEEK_END);          // Jump to the end of the file
    *filelen = ftell(fp);             // Get the current byte offset in the file
    rewind(fp);                      // Jump back to the beginning of the file

    *buffer = (char *)frmalloc((*filelen+1)*sizeof(char)); // Enough memory for file + \0
    fread(*buffer, *filelen, 1, fp); // Read in the entire file
    fclose(fp); // Close the file

    return 0;
}
